import { JSEncrypt } from 'jsencrypt'
// import request from './request'


// rsa的私钥
const resPrivateKey = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAKdXslbdxnzYaZvXFBya4orLpy52b7iXbnvNzOaejq1yDUoKFVX8PfJ2QU7BudMejGGnXQUKLtCKKDh9R8gXc2MIBwiIGw+CmnoIC7Pn/nZqQKYi05DUzc97AVhw59l09rbOgjrEWE1G2PZf4iEZE1rCSJ3ZBGId8xYbU9zbgV8zAgMBAAECgYAmNOSX5qyxxmteVF3YJhjBHbw+5HWfjJuCErvMj7j9qsOT+vdiGWQ/XnaMt7hollnw1dhsFSYZIOIL+7aO3aPPQkfgqfbGoeK8fxulWg44UWa7xRFcYZ1clddQsItwZowtcN1+pSziSGvq2B4VpVnTqn0GpjJ2C4ub8KpMnPXKEQJBAOnJ24stayXJ4ktS8ZCFZ3VACdufy9WDRvOmXTCdj8XEY+7rJcOAEdowUydvCEYChbUx1JY7IJ83dVCbZ0CtiosCQQC3PcIlVPgq5uVqA9eUMxgH/gqMVkDZR5ZQpJeCQoEVRnppSI+K69kg9zbNDvZ6wkA7mJ9+i6jmpBhYDYUZ2pr5AkEAhCKr7GjaQ3xsY2hY0fckd1efertBaMcO5g0kZKLZLM0IMnRDXtDWxjxD82jFA1TPn46vec2nbXXZ35pF7H9pawJBAJHgI4fuveYBjM86IcwEZPQv5JvWKqgPGnY2obr8UKDsS5U3Q7bXjTJ2O/VBHS2bKOGI3igy7JI4Pn0SvkxXwJkCQQDchIblP2CJ6QrbrGJUEwFLm+hoickN2ZzYvQEdXkBPowghps8FHjznu80NfGfBThngYr+Zt/GXlu1A04hZ+5dZ";
// rsa非对称加密
export default {
    // rsa解密加密后的aes秘钥
    decryptKey: (rsaEncryptAESKey: string) => {
        let decrypt = new JSEncrypt();
        decrypt.setPrivateKey(resPrivateKey);
        return decrypt.decrypt(rsaEncryptAESKey);
    }

    // async function (str: string) {
    //     return new Promise((resolve, reject) => {
    //         // 请求获取rsa加密的公钥
    //         request.get("/user/getPublicKey").then(res => {
    //             if (res) {
    //                 // 创建JSEncrypt实例
    //                 let encrypt = new JSEncrypt();
    //                 // 获取后端返回前端的公钥
    //                 let PublicKey = res.data.data;
    //                 // 设置公钥
    //                 encrypt.setPublicKey(PublicKey);
    //                 // 使用公钥进行加密
    //                 let newStr = encrypt.encrypt(str);
    //                 // console.log(newStr);

    //                 // 返回加密后的字符串对象
    //                 resolve({
    //                     str: newStr
    //                 })
    //             }
    //         }).catch(err => {
    //             console.log("rsa error");
    //         })
    //     })
    // },
}